package com.example.mybatislearn.config;

import com.example.mybatislearn.common.mapper.SmartDozerMapper;
import com.example.mybatislearn.common.mapper.SmartMapper;
import com.example.mybatislearn.common.mapper.converter.customer.impl.EnumTDConverter;
import com.example.mybatislearn.common.mapper.mapping.SmartBeanMapping;
import com.example.mybatislearn.domain.User;
import com.example.mybatislearn.dto.response.UserResponse;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class SmartMapperConfig {


    @Bean
    public SmartMapper createSmartMapper() {
        SmartDozerMapper smartDozerMapper = new SmartDozerMapper();

        //全局类型转化器
        smartDozerMapper.addCustomConterver(new EnumTDConverter());


        //自定义类型添加属性字段映射
        smartDozerMapper.addBeanMapping(create());

        return smartDozerMapper;
    }

    private SmartBeanMapping create() {
        return SmartBeanMapping.create(User.class, UserResponse.class).fields("userType","dictionaryItemDto");
    }
}
